package com.totoro.springcloud.hystrix_message.demo;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * Created by Niki on 2018/5/2 16:42
 */
public class HystrixCommandDemo extends HystrixCommand<String> {
    private final String name;

    protected HystrixCommandDemo(String name) {
        super(HystrixCommandGroupKey.Factory.asKey("DemoGroup"));
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        //业务逻辑，由Hystrix调用执行
        return "Hello " + name +" thread:" + Thread.currentThread().getName();
    }

    public static void main(String[] args) {
        String result = new HystrixCommandDemo("Niki").execute();
        System.out.println(result);
    }
}
